import http from "@/utils/http";
import { headerCommon, headerMaster } from "../header";
import { SupplierListData, SupplierData } from "./res";
import { SupplierSearchData, SupplierAddData, PaginationType } from "./param";

enum API {
    GET_SUPPLIER_LIST_API = '/1.1/classes/supplier',
    DELETE_SUPPLIER_API = '/1.1/classes/supplier',
    POST_SUPPLIER_ADD_API = "/1.1/classes/supplier",
    GET_SUPPLIER_DETAIL_API = '/1.1/classes/supplier',
    PUT_SUPPLIER_UPDATE_API = '/1.1/classes/supplier',
}

// 获取供应商退货列表
export const getSupplierListApi = (data?: SupplierSearchData, params?: PaginationType) =>
    http.get<any, SupplierListData>(API.GET_SUPPLIER_LIST_API + `${data ? `?where=${JSON.stringify(data)}` : ""}`, {
        headers: headerCommon,
        ...(params ? { params: { limit: params.pageSize, skip: (params.currentPage - 1) * params.pageSize } } : {})
    })

// 删除供应商退货
/**
 * 
 * @param objectId 
 * @returns 
 */
export const deleteSupplierApi = (objectId: string) =>
    http.delete<any, any>(API.DELETE_SUPPLIER_API + `/${objectId}`, {
        headers: headerMaster
    })

// 新增供应商退货
export const postSupplierAddApi = (data: SupplierAddData) =>
    http.post<any, any>(API.POST_SUPPLIER_ADD_API, data, { headers: headerCommon })

/**
 * 
 * @param objectId 
 * @returns 
 */
// 获取供应商退货详情
export const getSupplierDetailApi = (objectId: string) =>
    http.get<any, SupplierData>(API.GET_SUPPLIER_DETAIL_API + `/${objectId}`, {
        headers: headerCommon,
    })

/**
 * 
 * @param data 
 * @returns 
 */
// 更新供应商退货
export const putSupplierUpdateApi = (data: SupplierAddData) =>
    http.put<any, any>(API.PUT_SUPPLIER_UPDATE_API + `/${data.objectId}`, data, {
        headers: headerMaster
    })